<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //在ES6之前，我们无法给一个函数参数设置默认值，只能采用变通写法
        function add(a, b) {
            //判断b是否为空，为空就给默认值1
            b = b || 1;
            return a + b;
        }
        //传一个参数
        console.log(add(10));

        //现在可以这么写：直接给参数写上默认值，没传就会自动使用默认值
        function add2(a, b = 1) {
            return a + b;
        }
        console.log(add2(20));

        //不定参数
        function add3(...values) {
            console.log(values.length)

        }
        add3(1, 2)
        add3(1, 2, 3, 4)

        //箭头函数
        // var print=function(obj){
        //     console.log(obj);
        // }
        var print = obj => console.log(obj);
        print("hello");

        // var add4 = function (a, b) {
        //     return a + b;
        // }

        // var add4 = (a, b) => a + b;
        var add4 = (a, b) => {
            let c = a + b;
            return a + c;
        };

        console.log("add4:", add4(1, 2));

        //箭头函数+解构表达式
        const person = {
            name: 'jack',
            age: 21,
            language: ['java', 'js', 'css']
        };
        function hello(person) {
            console.log("hello," + person.name);
        }
        hello(person)

        var hello2 = (param) => console.log("hello," + param.name);
        hello2(person)

        var hello3 = ({ name }) => console.log("hello," + name);
        hello3(person)

    </script>
</body>

</html>